{\rtf1\ansi\deff0\adeflang1025
{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Times New Roman;}{\f4\fmodern\fprq1\fcharset0 Courier New;}{\f5\fswiss\fprq2\fcharset128 Microsoft Sans Serif;}{\f6\fswiss\fprq2\fcharset0 Arial Unicode MS;}{\f7\fnil\fprq2\fcharset0 MS Mincho;}{\f8\fnil\fprq0\fcharset0 Tahoma;}}
{\colortbl;\red0\green0\blue0;\red128\green128\blue128;}
{\stylesheet{\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\snext1 Normal;}
{\s2\sb240\sa120\keepn\rtlch\af2\afs28\lang255\ltrch\dbch\af7\langfe255\hich\f2\fs28\lang1033\loch\f2\fs28\lang1033\sbasedon1\snext3 Heading;}
{\s3\sa120\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon1\snext3 Body Text;}
{\s4\sa120\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon3\snext4 List;}
{\s5\sb120\sa120\rtlch\af8\afs24\lang255\ai\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\i\loch\fs24\lang1033\i\sbasedon1\snext5 caption;}
{\s6\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon1\snext6 Index;}
{\s7\sb120\sa120\rtlch\afs24\lang255\ai\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\i\loch\fs24\lang1033\i\sbasedon1\snext7 caption;}
{\s8\rtlch\af4\afs20\lang255\ltrch\dbch\af4\langfe255\hich\f4\fs20\lang1033\loch\f4\fs20\lang1033\sbasedon1\snext8 Preformatted Text;}
}
{\info{\creatim\yr2011\mo7\dy19\hr6\min24}{\revtim\yr0\mo0\dy0\hr0\min0}{\printim\yr0\mo0\dy0\hr0\min0}{\comment StarWriter}{\vern3000}}\deftab709
{\*\pgdsctbl
{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Standard;}}
{\*\pgdscno0}\paperh15840\paperw12240\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
\pard\plain \ltrpar\s1\ql\rtlch\af5\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f5\fs20\lang1033\loch\f5\fs20\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Content;}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\f5\fs20\lang1033\loch\f5\fs20\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Core;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Graphics;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Math;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Scene;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 using Tesla.Scene.Shape;}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\f5\fs20\lang1033\loch\f5\fs20\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 namespace TeslaSamples.Renderer \{}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 [AppDescription("Hardware Instancing", PlatformCapabilities.Direct3D10 | PlatformCapabilities.XNA4, "InstancingImage", "InstancingDesc", "InstancingSource")]}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 public class InstancingSample : BasicApp \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private Mesh mesh;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private Sphere sphere;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private int numInstances = 256;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private VertexBuffer worldTransforms;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private Matrix[] transformArray;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private Material material;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private VertexBufferBinding[] buffers;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 private float acctime = 0;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 protected override void LoadContent() \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 this.ClearColor = Color.Black;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Let's create a mesh that will serve as our data. We're technically not using the scene graph here, this is just a convience.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Maybe at some point the engine's scene graph will have a mesh structure that supports instancing, for now we have to do it ourselves.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 mesh = new Box("Box", 2, 2, 5);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 mesh.SetRandomColors();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //We use the default lights from the root node, so all our instances will be lit.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 mesh.Lights.Set(RootNode.Lights);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 mesh.UpdateWorldLights(false);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Create a target object that all our instances will "look at"}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 sphere = new Sphere("Sphere", 30, 30, 10);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 sphere.Material = ContentManager.Load<Material>("LitBasicColor.tem").Clone();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 sphere.Material.SetParameter("MatDiffuse", Color.Yellow.ToVector3());}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 RootNode.AddChild(sphere);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 // The mesh will have a vertex buffer that goes something like so:}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Position0 - Vector3}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Normal0 - Vector3}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Color0 - Color}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //TexCoord0 - Vector2}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 // Meanwhile, our second vertex buffer that contains the world transforms will look like this, since we're passing a 4x4 matrix:}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //TexCoord0 - Vector4}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //TexCoord1 - Vector4}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //TexCoord2 - Vector4}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //TexCoord3 - Vector4}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 // When we set these two buffers at the same time (first to slot 0, second to slot 1), the engine automatically}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //merges the declarations and resolves conflicts such as duplicate semantic indices - in the order the}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //vertex buffers are set to the device, so in this example the semantic indices of the second buffer are all incremented}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //by one.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 VertexDeclaration decl = new VertexDeclaration(new VertexElement[] \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 new VertexElement(VertexSemantic.TextureCoordinate, 0, VertexFormat.Vector4, 0),}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 new VertexElement(VertexSemantic.TextureCoordinate, 1, VertexFormat.Vector4, 16),}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 new VertexElement(VertexSemantic.TextureCoordinate, 2, VertexFormat.Vector4, 32),}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 new VertexElement(VertexSemantic.TextureCoordinate, 3, VertexFormat.Vector4, 48)}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \});}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //We want a dynamic vertex buffer for the world transforms since we'll be updating each instance's}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //rotation to "look at" the sphere.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 worldTransforms = new VertexBuffer(decl, numInstances, ResourceUsage.Dynamic);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 transformArray = new Matrix[numInstances];}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 int index = 0;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Set the instances into a 2D grid on the XY plane.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 for (int x = 0; x < 16; x++) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 for (int y = 0; y < 16; y++) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 Matrix transform = Matrix.FromTranslation(new Vector3((x - 7.5f) * 15.0f, (y - 7.5f) * 15.0f, 0.0f));}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 transformArray[index++] = transform;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch            }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 worldTransforms.SetData<Matrix>(transformArray);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Setup our vertex buffer bindings - the world transforms are set to an instance frequency of one, so for each}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //instance we'll use one "vertex" from that buffer (which is the world transform)}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 buffers = new VertexBufferBinding[] \{ mesh.MeshData.VertexBuffer, new VertexBufferBinding(worldTransforms, 0, 1) \};}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 //Load a material we've created}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 material = ContentManager.Load<Material>("Materials//InstancedMaterial.tem");}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 material.SetParameter("DiffuseMap", ContentManager.Load<Texture>("Textures//rock_diff.dds"));}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 protected override void OnUpdate(GameTime time) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 acctime += (float) Engine.ValueMap.TimePerFrame;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 sphere.Translation = new Vector3((float)System.Math.Sin(acctime) * 70, (float)System.Math.Cos(acctime) * 70, (float)System.Math.Cos(acctime) * 40);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 for(int i = 0; i < transformArray.Length; i++) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 Matrix transform = transformArray[i];}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 Vector3 pos = transform.Translation;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 transformArray[i] = Matrix.LookAt(pos, sphere.Translation, Vector3.Up) * Matrix.FromTranslation(pos);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 worldTransforms.SetData<Matrix>(transformArray, DataWriteOptions.Discard);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 protected override void OnRender(IRenderer renderer) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 Engine.ValueMap.WorldMatrix = Matrix.Identity;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 material.ApplyMaterial(renderer, mesh);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 material.ApplyPass(renderer, 0);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 renderer.RasterizerState = RasterizerState.CullBackClockwiseFront;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 MeshData md = mesh.MeshData;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 renderer.SetVertexBuffers(buffers);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 renderer.SetIndexBuffer(md.IndexBuffer);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 renderer.DrawIndexedInstanced(md.PrimitiveType, md.IndexCount, 0, 0, numInstances);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f5\fs20\loch\f5\fs20 \}}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af6\langfe255\hich\f5\fs20\lang1033\loch\f5\fs20\lang1033 {\rtlch \ltrch\loch\f5\fs20\lang1033\i0\b0 \}}
\par }